package datastructures;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


public class OpenList {

	ArrayList<MyNode> list = new ArrayList<MyNode>();
	private Comparator<MyNode> comparator;

	public OpenList(Comparator<MyNode> aComparator) {
		this.list = new ArrayList<MyNode>();
		this.comparator = aComparator;
	}
	
	public boolean isEmpty() {
		if (this.list.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	public void sort() {
		Collections.sort(list, comparator);
	}

	//return first node in list and removes it
	public MyNode getFirstNode() {
		MyNode node = this.list.get(0); 
		this.list.remove(0);
		return node;
	}
	
	public MyNode getLastNode() {
		MyNode node = this.list.get(this.list.size() - 1);
		this.list.remove(this.list.size() - 1);
		
		return node;
	}

	//fuegt eine liste von nodes an den beginn der openlist ein
	public void addFirst(ArrayList<MyNode> nodes) {
		ArrayList<MyNode> tempList = new ArrayList<MyNode>();
		
		tempList.addAll(nodes);
		tempList.addAll(this.list);
			
		this.list = tempList;
	}
	
	
	public void add(List<MyNode> nodes) {
		this.list.addAll(nodes);
		this.sort();
		
	}
	
	public void add(MyNode node) {
		this.list.add(node);
		this.sort();
		
	}
	
	public boolean contains(MyNode node) {
		return this.list.contains(node);
		
	}
	
}
